library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0 ✔ purrr 0.3.5
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.4.1
## ✔ readr 2.1.3 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
library(countrycode)
#setwd("C:/Users/Anna/Desktop/Hertie/second_year/GHG-project")
owid <- read_csv("owid-co2-data.csv")
Which states contribute to production-based emissions and consumption-based emissions the most? Are these the same states? What are the differences? How does this change when we look at the regions? Which regions contribute the most? What are the differences in share between states with the highest and lowest GDP (per capita)?
owid <-owid%>%mutate(gdp_per_capita=gdp/population)
figure_1 <- owid %>%
filter(!is.na(consumption_co2))%>% filter(country %in% c("World", "Africa", "North America", "Europe (excl. EU-28)", "South America", "Asia", "Australia", "Asia (excl. China & India)", "European Union (28)", "North America (excl. USA)", "Oceania"))%>%
filter(year==2018) %>%
arrange(desc(consumption_co2)) %>%
ggplot(.,aes(x=consumption_co2,y=reorder(country,consumption_co2))) +
geom_col(color="#636363",fill="#BD1550") +
scale_fill_brewer(palette="Set2") +
theme_bw() +
theme(axis.title.y = element_blank()) +
xlab("") +
ggtitle("Consumption of CO2 per Region in 2018")+guides(fill=guide_legend(title=" "))
ggsave("Fig. 1 Consumption by Region 2018", plot = figure_1, device = "png", width = 10, height = 8)
figure_2 <- owid %>% filter(!is.na(cumulative_co2))%>% filter(country %in% c("World", "Africa", "North America", "Europe (excl. EU-28)", "South America", "Asia", "Australia", "Asia (excl. China & India)", "European Union (28)", "North America (excl. USA)", "Oceania"))%>%
filter(year==2018) %>%
arrange(desc(cumulative_co2)) %>%
ggplot(.,aes(x=cumulative_co2,y=reorder(country,cumulative_co2))) +
geom_col(color="#636363",fill="#490A3D") +
theme_bw() +
theme(axis.title.y = element_blank()) +
xlab("") +
ggtitle("Production of CO2 per Region in 2018")+guides(fill=guide_legend(title=" "))
ggsave("Fig. 2 Production by Region 2018", plot = figure_2, device = "png", width = 10, height = 8)
figure_3 <- owid %>%
filter(country %in% c("Africa", "North America", "Europe", "South America", "Asia", "Australia", "Asia (excl. China & India)", "North America (excl. USA)", "Oceania")) %>%
ggplot(.,aes(x=year,y=consumption_co2,fill=country)) +
geom_area(color="#636363", position="fill") +
theme_bw() +
scale_fill_brewer(palette="RdPu") +
ylab("") +
theme(axis.title.x=element_blank()) +
ggtitle(paste0("Share of CO2 Consumption across Regions since 1990"))+guides(fill=guide_legend(title=" "))
ggsave("Fig. 3 share of consumption by region s1990", plot = figure_3, device = "png", width = 10, height = 8)
figure_4 <- owid %>% filter(year>1990) %>%
filter(country %in% c("Africa", "North America", "Europe", "South America", "Asia", "Australia", "Asia (excl. China & India)", "North America (excl. USA)", "Oceania")) %>%
ggplot(.,aes(x=year,y=cumulative_co2,fill=country)) +
geom_area(color="#636363", position="fill") +
theme_bw() +
scale_fill_brewer(palette="BuPu") +
ylab("") +
theme(axis.title.x=element_blank()) +
ggtitle(paste0("Share of CO2 Production across Regions since 1990"))+guides(fill=guide_legend(title=" "))
ggsave("Fig. 4 share of production by region s1990", plot = figure_4, device = "png", width = 10, height = 8)
figure_1
figure_2
figure_3
figure_4
figure_5 <- owid %>% filter(!is.na(consumption_co2))%>% filter(!country %in% c("World", "Africa", "North America", "Europe (excl. EU-28)", "South America", "Asia", "Australia", "Asia (excl. China & India)", "European Union (28)", "Europe","Europe (excl. EU-27)", "European Union (27)", "High-income countries", "Upper-middle-income countries", "Lower-middle-income countries", "North America (excl. USA)","Oceania" ))%>%
filter(year==2018) %>%
arrange(desc(consumption_co2)) %>%
head(10) %>%
ggplot(.,aes(x=consumption_co2,y=reorder(country,consumption_co2))) +
geom_col(color="#636363",fill="#BD1550") +
scale_fill_brewer(palette="Set2") +
theme_bw() +
theme(axis.title.y = element_blank()) +
xlab("") +
ggtitle("Consumption of CO2 per country in 2018")
ggsave("Fig. 5 consumption by country 2018", plot = figure_5, device = "png", width = 10, height = 8)
figure_6 <- owid %>% filter(!is.na(consumption_co2)) %>%
filter(!country %in% c("World", "Africa", "North America", "Europe (excl. EU-28)", "South America", "Asia", "Australia", "Asia (excl. China & India)", "European Union (28)", "Europe","Europe (excl. EU-27)", "European Union (27)", "High-income countries", "Upper-middle-income countries", "Lower-middle-income countries", "North America (excl. USA)", "Oceania" )) %>%
filter(year==2018) %>%
arrange(desc(cumulative_co2)) %>%
head(10) %>%
ggplot(.,aes(x=cumulative_co2,y=reorder(country,cumulative_co2))) +
geom_col(color="#636363",fill="#490A3D") +
theme_bw() +
theme(axis.title.y = element_blank()) +
xlab("") +
ggtitle("Production of CO2 per country in 2018")
ggsave("Fig. 6 production by country 2018", plot = figure_6, device = "png", width = 10, height = 8)
figure_5
figure_6
figure_7 <- owid %>% filter(year>1990) %>%
filter(country %in% c( "High-income countries", "Upper-middle-income countries", "Lower-middle-income countries", "Low-income countries")) %>%
ggplot(.,aes(x=year,y=consumption_co2,fill=country)) +
geom_area(color="#636363", position="fill") +
theme_bw() +
scale_fill_brewer(palette="RdPu") +
ylab("") +
theme(axis.title.x=element_blank()) +
ggtitle(paste0("Share of consumption based CO2 emissions by income"))+guides(fill=guide_legend(title=" "))
ggsave("Fig. 7 consumption by income s1990", plot = figure_1, device = "png", width = 10, height = 8)
figure_8 <- owid %>% filter(year>1990) %>%
filter(country %in% c("High-income countries", "Upper-middle-income countries", "Lower-middle-income countries", "Low-income countries")) %>%
ggplot(.,aes(x=year,y=cumulative_co2,fill=country)) +
geom_area(color="#636363", position="fill") +
theme_bw() +
scale_fill_brewer(palette="BuPu") +
ylab("") +
theme(axis.title.x=element_blank()) +
ggtitle(paste0("Share of CO2 production based CO2 emissions by income"))+guides(fill=guide_legend(title=" "))
ggsave("Fig. 8 production by income s1990", plot = figure_1, device = "png", width = 10, height = 8)
figure_7
figure_8
owid_bubbles <- owid %>%
filter(!is.na(country))%>% filter(!country %in% c("World", "Africa", "North America", "Europe (excl. EU-28)", "South America", "Asia","Asia (excl. China & India)", "European Union (28)", "Europe","Europe (excl. EU-27)", "European Union (27)", "High-income countries", "Upper-middle-income countries", "Lower-middle-income countries", "North America (excl. USA)", "Oceania", "International transport", "Kuwaiti Oil Fires")) %>%
mutate(continent = countrycode(iso_code, origin = "iso3c", destination = "continent"))
## Warning in countrycode_convert(sourcevar = sourcevar, origin = origin, destination = dest, : Some values were not matched unambiguously: ATA
figure_9 <- owid_bubbles %>%filter(year==2018) %>% filter(!is.na(gdp_per_capita)&!is.na(cumulative_co2)&!is.na(consumption_co2))%>%arrange(desc(gdp_per_capita)) %>%
head(12) %>% plot_ly( x = ~cumulative_co2, y = ~consumption_co2, type = 'scatter', mode = 'markers', size = ~gdp_per_capita, color = ~country, colors = 'Paired',
sizes = c(50, 1000))
figure_9 <- figure_9 %>%
layout(title = 'Consumption vs production based emissions (top 12 by GDP per capita)',
xaxis = list(title = 'Production of CO2 in million tonnes'),
yaxis = list(title = 'Consumption of CO2 in million tonnes'))
htmlwidgets::saveWidget(figure_9, file = "figure_9.html")
figure_9
figure_10 <- owid_bubbles %>%
filter(year==2018) %>%
filter(!is.na(gdp_per_capita)&!is.na(cumulative_co2)&!is.na(consumption_co2)) %>%
arrange(desc(gdp_per_capita)) %>%
slice_min(gdp_per_capita,n=12) %>%
plot_ly( x = ~cumulative_co2, y = ~consumption_co2, type = 'scatter', mode = 'markers', size = ~gdp_per_capita, color = ~country, colors = 'Paired',
sizes = c(50, 1000))
figure_10 <- figure_10 %>%
layout(title = 'Consumption vs production based emissions (bottom 12 by GDP per capita)',
xaxis = list(title = 'Production of CO2 in million tonnes'), yaxis = list(title = 'Consumption of CO2 in million tonnes'))
figure_10
htmlwidgets::saveWidget(figure_10, file = "figure_10.html")
total <- owid %>%
filter(country=="World") %>%
filter(year==2018) %>%
select(consumption_co2)
with_share <- owid %>%
filter(year==2018) %>%
filter(!is.na(gdp_per_capita)) %>%
mutate(share=(consumption_co2/36646.14)*100)
top_share<-with_share%>%arrange(desc(gdp_per_capita))%>%slice(1:10)%>%select(country, share)
top_share %>%
arrange(desc(share))
## # A tibble: 10 × 2
## country share
## <chr> <dbl>
## 1 United States 15.6
## 2 United Arab Emirates 0.560
## 3 Switzerland 0.328
## 4 Singapore 0.310
## 5 Hong Kong 0.297
## 6 Kuwait 0.240
## 7 Qatar 0.188
## 8 Norway 0.133
## 9 Ireland 0.115
## 10 Luxembourg 0.0633
total_production <- owid %>%
filter(country=="World") %>%
filter(year==2018) %>%
select(cumulative_co2)
with_share_production <- owid %>%
filter(year==2018) %>%
filter(!is.na(gdp_per_capita)) %>%
mutate(share=(cumulative_co2/1625014)*100)
top_share_production <- with_share_production %>%
arrange(desc(gdp_per_capita)) %>%
slice(1:10)%>%select(country, share)
top_share_production %>%
arrange(desc(share))
## # A tibble: 10 × 2
## country share
## <chr> <dbl>
## 1 United States 25.0
## 2 United Arab Emirates 0.270
## 3 Switzerland 0.182
## 4 Kuwait 0.166
## 5 Norway 0.157
## 6 Ireland 0.133
## 7 Singapore 0.127
## 8 Qatar 0.115
## 9 Hong Kong 0.0952
## 10 Luxembourg 0.0453
df<-owid%>% group_by(country, year)%>% filter(!country %in% c("World", "Africa", "North America", "Europe (excl. EU-28)", "South America", "Asia","Asia (excl. China & India)", "European Union (28)", "Europe","Europe (excl. EU-27)", "European Union (27)", "High-income countries", "Upper-middle-income countries", "Lower-middle-income countries", "North America (excl. USA)", "Oceania", "International transport", "Kuwaiti Oil Fires"))%>%summarise(sum_em=sum(cumulative_co2, na.rm=T))
## `summarise()` has grouped output by 'country'. You can override using the
## `.groups` argument.
df2<-df%>%select(country, sum_em, year)%>%mutate(prop=(sum_em/sum(sum_em))*100)
figure_11<-df2%>% filter(year>1990)%>% filter(country %in% c("China", "United States", "Germany"))%>%
ggplot(.,aes(x=year,y=prop,fill=country)) +
geom_area(color="#636363") +
theme_bw() +
scale_fill_brewer(palette="BuPu") +
ylab("% of total share") +
theme(axis.title.x=element_blank()) +
ggtitle(paste0("trends in overall share in production over time"))+guides(fill=guide_legend(title=" "))
#"Russia", "United Kingdom", "Japan", "India", "France", "Canada"
df3<-owid%>% group_by(country, year)%>% filter(!country %in% c("World", "Africa", "North America", "Europe (excl. EU-28)", "South America", "Asia","Asia (excl. China & India)", "European Union (28)", "Europe","Europe (excl. EU-27)", "European Union (27)", "High-income countries", "Upper-middle-income countries", "Lower-middle-income countries", "North America (excl. USA)", "Oceania", "International transport", "Kuwaiti Oil Fires"))%>%summarise(sum_em=sum(consumption_co2, na.rm=T))
## `summarise()` has grouped output by 'country'. You can override using the
## `.groups` argument.
df4<-df3%>%select(country, sum_em, year)%>%mutate(prop=(sum_em/sum(sum_em))*100)
figure_12<-df4%>% filter(year>1990)%>% filter(country %in% c("China", "United States", "India"))%>%
ggplot(.,aes(x=year,y=prop,fill=country)) +
geom_area(color="#636363") +
theme_bw() +
scale_fill_brewer(palette="RdPu") +
ylab("% of total share") +
theme(axis.title.x=element_blank()) +
ggtitle(paste0("Trends in overall share in consumption over time"))+guides(fill=guide_legend(title=" "))
#"Russia", "United Kingdom", "Japan", "India", "France", "Canada"